package com.service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.db.domain.Record;
import com.excel.read.Config;
import com.excel.read.DBTable;
import com.operation.RecordOperation;

public class TableCreateService {

	public static void main(String[] args) {

		Config.generateTable("c:\\table_config.xls");
		String[] names = Config.allTable.getTableNames();
		for(String tableName : names) {
		DBTable dbTable = (DBTable) Config.allTable.get(tableName.toString());
		List<String> strs = dbTable.getScript();
		execute(strs);
		}
//		System.out.println(str);

	}
	
	public static long execute(List<String> strs) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ResultSet res = null;
		try {
			
			// 加载Connector/J驱动
			Class.forName("com.mysql.jdbc.Driver");
			// Class.forName("org.postgresql.Driver").newInstance();
			// 建立到MySQL的连接
			conn = DriverManager.getConnection(
					"jdbc:mysql://localhost:3308/sync", "root", "666666");
			conn.setAutoCommit(false);
			// 执行SQL语句
			for(String sql :strs) {
				pstmt = conn.prepareStatement(sql);
				pstmt.executeUpdate();
				pstmt.getConnection().commit();
			}
			
					
				
			
		} catch (SQLException ex) {
			System.out.println("Error : " + ex.toString());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				pstmt.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		return 0;
	}

}
